<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline" style="padding-left: 5px;">
            <input type="text" name="username" lay-verify="title" placeholder="Input username" autocomplete="off"
                   class="layui-input" value="" style="width: 200px;">
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <a href="{:url('usdtAdd')}" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe608;</i>Add</a>
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
                <a href="javascript:;" class="layui-btn layui-btn-sm update_usdt">更新USDT全局汇率</a>
            </div>
        </div>
    </div>
</form>
<div class="table-body">
    <table id="balanceTable" lay-filter="balanceTable"></table>
</div>
<script>
    layui.use(['form', 'laydate', 'table',], function () {
        var laydate = layui.laydate,
            form = layui.form,
            table = layui.table; //表格
        //时间插件
        laydate.render({
            elem: '#datetime',
            range: '_',
            format: 'yyyy-MM-dd'
        });
        var userTables = table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            totalRow: true,
            method: 'post',
            url: "{:url('usdtUser')}",
            id: 'balanceTable',
            cols: [[
                { type: 'numbers'},
                { field: 'username',  align: 'left', title: 'username',width:180},
                { field: 'rate',  align: 'rate', title: '手续费率',width:180},
                { field: 'check_time', align: 'center', title: '创建时间' , width: 160,
                    templet: function (d) {
                        return layui.util.toDateString(d.time * 1000, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                {
                    field: 'operating', title: '操作', width: 250, align: 'center', templet: function (data) {
                        var html = '';
                        html += '<a class="layui-btn layui-btn-xs option-edit" data-id="' + data.id + '">编辑</a>';
                        html += '<a class="layui-btn layui-btn-xs option-del layui-btn-danger" data-id="' + data.id + '">删除</a>';
                        return html;
                    }
                },
            ]],
            page: true,
            limit: 50,
            limits: [50,1000, 10000],
        });
        form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //角色删除
        $(document).on('click', '.option-del', function () {
            var id = $(this).attr('data-id');
            layer.confirm('您确定删除此用户吗？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                //去删除
                JsPost("{:url('del')}", { 'id': id }, function (res) {
                    if (res.status) {
                        layer.msg('删除成功');
                        userTables.reload();
                    } else {
                        layer.msg(res.msg);
                    }
                });
            }, function () {
                layer.close(1);
            });
        });

        $(document).on('click', '.option-edit', function () {
            var id = $(this).attr('data-id');
            JsGet('{:url("edit")}?id=' + id, function (e) {
                if(e.status == 1){
                    layer.open({
                        type: 1,
                        title: 'Usdt Edit',
                        area: ['600px', '400px'], //宽高
                        content: e.datas,
                        btn:['Confirm','Close'],
                        yes:function (index,layero) {
                            var thedata = $('.operationForm').serialize();
                            JsPost('{:url("edit")}', thedata,function (re) {
                                if(re.status >0){
                                    layer.msg(re.msg , {icon:1,time:1500});
                                    layer.close(index);
                                    userTables.reload({
                                        page:{
                                            curr :1
                                        }
                                    });
                                }else{
                                    layer.msg(re.msg, {icon:2,time:1500});
                                }
                            });
                        }
                    });
                }else{
                    layer.msg(e.msg);
                }
            });
        });

        $(document).on('click', '.update_usdt', function () {
            JsGet('{:url("usdtRate")}', function (e) {
                if(e.status == 1){
                    layer.open({
                        type: 1,
                        title: '更新全部用户汇率',
                        area: ['600px', '400px'], //宽高
                        content: e.datas,
                        btn:['Confirm','Close'],
                        yes:function (index,layero) {
                            var thedata = $('.operationForm').serialize();
                            JsPost('{:url("usdtRate")}', thedata,function (re) {
                                if(re.status >0){
                                    layer.msg(re.msg , {icon:1,time:1500});
                                    layer.close(index);
                                    userTables.reload({
                                        page:{
                                            curr :1
                                        }
                                    });
                                }else{
                                    layer.msg(re.msg, {icon:2,time:1500});
                                }
                            });
                        }
                    });
                }else{
                    layer.msg(e.msg);
                }
            });
        });
    });
</script>